﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ExpenseSystem.Model;
using ExpenseSystem.Lor;
using ExpenseSystem.Common;
using ExpenseSystem.DataUpdater;
using ExpenseSystem.Fether;
using ExpenseSystem.Core.DataAddOn;

namespace ExpenseSystem.Core.OrderModules
{
    public class OrderBaseManager:OrderManager
    {
        OrderFetcher fetcher = new OrderFetcher();
        public override bool Delete(OrderModel Order,  out string message)
        {
            if (Order.Site != profile.SiteId)
            {
                message = "当前登录的组织与档案所在组织不一致";
                return false;
            }
            if (profile.SpCtl && Order.SalesPointId != profile.SalesPoint)
            {
                message = "当前登录的门店与档案所在门店不一致";
                return false;
            }
            bool result = OrderUpdater.Remove(Order, tran, fetcher, out message);
            return result;
        }

        public override bool DeleteById( long[] OrderIds,  out string message)
        {
            bool result = true;
            result = OrderUpdater.RemoveById( profile.SiteId, OrderIds, tran, fetcher, out message);
            return result;
        }

        public override bool Save( OrderModel Order,  out string message, params IAddable<OrderModel>[] addable)
        {
            if (Order.Site != profile.SiteId)
            {
                message = "当前登录的组织与档案所在组织不一致";
                return false;
            }
            if(profile.SpCtl&&Order.SalesPointId!=profile.SalesPoint)
            {
                message = "当前登录的门店与档案所在门店不一致";
                return false;
            }
            bool result = true;
            result = OrderUpdater.Save( Order, tran, fetcher, out message);
            return result;
        }
    }
}
